package logic

import (
	"context"
	"order/orderrpc/internal/models"

	"order/orderrpc/internal/svc"
	"order/orderrpc/pb/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PayLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPayLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PayLogic {
	return &PayLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PayLogic) Pay(in *orderrpc.PayRequest) (*orderrpc.PayResponse, error) {
	// todo: add your logic here and delete this line
	count, name, err := models.Pay(in.Cn)
	if err != nil {
		return &orderrpc.PayResponse{
			Count: 0,
			Name:  "",
		}, nil
	}
	return &orderrpc.PayResponse{
		Count: int32(count),
		Name:  name,
	}, nil
}
